//
//  PopUpTipsView.m
//  Toyota
//
//  Created by ld on 2024/6/25.
//

#import "PopUpTipsView.h"
#import "Definition.h"
#import "Helper.h"
@implementation PopUpTipsView
- (void)tipsWithTitle:(NSString *)titleStr andContent:(NSString *)contentStr andContentAlignment:(NSTextAlignment)textAlignment andBtnTitleArr:(NSArray *)btnTitleArr andbtnColorArr:(NSArray *)btnColorArr andBtnBgColorArr:(NSArray *)btnBgColorArr{
    
    _bgV = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.customWidth, self.customHeight)];
    _bgV.backgroundColor = [UIColor whiteColor];
    [_bgV rounded:8];
    [self addSubview:_bgV];
    UILabel * titleLab = [[UILabel alloc]initWithFrame:CGRectMake(0, 17, self.customWidth, 30)];
    titleLab.text = titleStr;
    titleLab.textAlignment = NSTextAlignmentCenter;
    titleLab.textColor = kColor141414;
    titleLab.font = fontBold(17);
    [_bgV addSubview:titleLab];
    
    float cellH = titleLab.customBottom;
    if (contentStr.length) {
        UILabel * contentLab = [[UILabel alloc]initWithFrame:CGRectMake(20, cellH + 15, self.customWidth - 40, 20)];
        contentLab.textColor = kColor141414;
        contentLab.font = fontSize(16);
        contentLab.text = contentStr;
        contentLab.numberOfLines = 0;
        contentLab.attributedText = [contentLab setupAttributeString:contentStr andFont:fontSize(14) andColor:kColor141414 andTextAlignment:(textAlignment) rangeLineHeight:9];
        [contentLab sizeToFit];
        contentLab.customWidth = self.customWidth - 40;
        [_bgV addSubview:contentLab];
        cellH = contentLab.customBottom;
    }
//    choiceBtn.frame = CGRectMake(CYScalW(20) + CYScalW((self.customWidth - 30) / 2.) * i, cellH + 20, CYScalW((self.customWidth - 40 - 10 * (btnTitleArr.count - 1)) / btnTitleArr.count), 40);
//    choiceBtn.frame = CGRectMake(CYScalW(20) + CYScalW(125) * i, cellH + 20, CYScalW(115), 40);
    for (int i = 0; i < btnTitleArr.count; i++) {
        UIButton * choiceBtn = [UIButton buttonWithType:(UIButtonTypeCustom)];
        choiceBtn.frame = CGRectMake(CYScalW(20) + (self.customWidth - CYScalW(30)) / 2. * i, cellH + 20, (self.customWidth - CYScalW(40) - CYScalH(10 * (btnTitleArr.count - 1))) / btnTitleArr.count, 40);
        [choiceBtn setTitle:btnTitleArr[i] forState:(UIControlStateNormal)];
        choiceBtn.backgroundColor = btnBgColorArr[i];
        [choiceBtn setTitleColor:btnColorArr[i] forState:(UIControlStateNormal)];
        choiceBtn.titleLabel.font = fontSize(16);
        [choiceBtn rounded:20 width:1 color:kColor141414];
        [choiceBtn addTarget:self action:@selector(choiceBtnAction:) forControlEvents:(UIControlEventTouchUpInside)];
        [_bgV addSubview:choiceBtn];
    }
    
    _bgV.customHeight = cellH + 75;
}

- (void)choiceBtnAction:(UIButton *)sender {
    if (self.choicActionBlock) {
        self.choicActionBlock(sender.titleLabel.text);
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
